import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

my_sender = "1006170239@qq.com"  # 发件人邮箱
my_pass = 'brbkiuyirjnjbeab'  # 授权码
my_user = '736510460@qq.com'  # 收件人邮箱


def mail():
    ret = True
    try:
        send_file = open(r'C:\Users\admin\PycharmProjects\Flag\allureReport','rb').read()
        msg = MIMEText('测试报告', 'plain', 'utf-8')  # 填写内容
        msg['From'] = formataddr(["李成伟", my_sender])  # 发件人邮箱昵称，账号
        msg['To'] = formataddr(["寻不尽天下", my_user])  # 收件人对应邮箱昵称，账号
        msg['subject'] = '测试报告'  # 邮件主题
        server = smtplib.SMTP_SSL('smtp.qq.com',465)  # 发件人邮箱中的SMTP服务器
        server.login(my_sender, my_pass)  # 括号中对应的是发件人邮箱账号，邮箱密码
        server.sendmail(my_sender, [my_user, ], msg.as_string())  # 括号中对应发件人邮箱账号，收件人邮箱账号，发送邮件
        server.quit()
    except Exception:
        ret = False
    return ret

ret = mail()
if ret:
    print('邮箱发送成功')
else:
    print('发送失败')
